package com.dit.sanasa_sme_vaadin;

import javax.servlet.annotation.WebServlet;

import com.dit.entity.UserLogin;
import com.dit.service.UserService;
import com.dit.util.SpringContextHelper;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
@Theme("sanasa_sme_vaadin")
public class Sanasa_sme_vaadinUI extends UI {

	@WebServlet(value = "/*", asyncSupported = true)
	@VaadinServletConfiguration(productionMode = false, ui = Sanasa_sme_vaadinUI.class)
	public static class Servlet extends VaadinServlet {
	}

	@Override
	protected void init(VaadinRequest request) {
		final VerticalLayout layout = new VerticalLayout();
		layout.setMargin(true);
		setContent(layout);

		Button button = new Button("Click Me");
		button.addClickListener(new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				layout.addComponent(new Label("Thank you for clicking"));
			}
		});
		layout.addComponent(button);
		
		SpringContextHelper helper = new SpringContextHelper(VaadinServlet
				.getCurrent().getServletContext());
		
		final UserService userService = (UserService) helper.getBean("userService");
		

		UserLogin user = userService.validateUser("admin", "admin");
		System.out.println(user.getUserType());
	}

}